package lcr;

public class Test0105 {
}

class Solution0105_1 {
    int length1 = 0;
    int length2 = 0;
    public int maxAreaOfIsland(int[][] grid) {
        this.length1 = grid.length;
        this.length2 = grid[0].length;
        int ans = 0;
        for (int i = 0; i < length1; i++) {
            for (int j = 0; j < length2; j++) {
                if (grid[i][j] == 1) {
                    ans = Math.max(ans, dfs(grid, i, j));
                }
            }
        }
        return ans;
    }

    public int dfs(int[][] grid, int i, int j) {
        if (i<0||j<0||i>=length1||j>= length2 ||grid[i][j] <= 0) return 0;
        grid[i][j] = -1;
        return 1 + dfs(grid, i + 1, j) + dfs(grid, i - 1, j) + dfs(grid, i, j + 1) + dfs(grid, i, j - 1);
    }
}
